// ========================================================
// Des：
// Autor：Mr.H 
// CreateTime：2024/04/06 09:17:01
// 版 本：v 1.0
// ========================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Timeline;

public class GamePanel : BasePanel<GamePanel>
{

    public CustomGUILabel labScore;
    public CustomGUILabel labTime;
    public CustomGUIButton btnQuit;
    public CustomGUIButton btnSetting;
    public CustomGUITexture texHP;
    //当前分数
    [HideInInspector]
    public int nowScore = 0;
    public float hpW = 300;
    [HideInInspector]
    public float nowTime = 0;

    private int time;

    // Start is called before the first frame update
    void Start()
    {
        btnQuit.clickEvent += () =>
        {
            //返回游戏界面
            //弹出确定按钮  
            SceneManager.LoadSceneAsync("BeginScene");
        };
        btnSetting.clickEvent += OpenSeetingPanel;

        // AddScore(100);
        // UpdateHP(100, 20);
    }

    // Update is called once per frame
    void Update()
    {
        //通过帧间隔时间  累加 较准确
        nowTime += Time.deltaTime;
        //把秒数 转换成 时  分 秒
        time = (int)nowTime;//向下取整
        labTime.content.text = "";
        //转换时间
        if (time / 3600 > 0)
        {
            labTime.content.text += time / 3600 + "时";
        }
        //8432-7200 余 1232s
        // 1232s / 60 ≈ 20分  
        if (time % 3600 / 60 > 0 || labTime.content.text != "")
        {
            labTime.content.text += time % 3600 / 60 + "分";
        }
        //1232s-1200 余 32秒
        labTime.content.text += time % 60 + "秒";
    }

    void OpenSeetingPanel()
    {
        SettingPanel.Instance.ShowMe();
        //改变时间 缩放值 为0就是时间停止
        Time.timeScale = 0;
    }

    /// <summary>
    /// 死亡时 加分
    /// </summary>
    /// <param name="score"></param>
    public void AddScore(int score)
    {
        nowScore += score;
        //更新界面显示
        labScore.content.text = nowScore.ToString();
    }

    public void UpdateHP(int maxHP, int HP)
    {
        texHP.guiPos.width = (float)HP / maxHP * hpW;
    }
}
